import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;

class MyComboBoxContainer extends MyComponentContainer { 
    int flag;
    String []arrangedColumnsNames;
    String tableNameOutput;
    String tableNameInput;
    String fieldNameInput;
    Vector allColumnsNames;
    Vector customizedTableData;
    
    MyComboBoxContainer(String name, MyFrame frame) {
        super(new JComboBox(), frame);
        fillComboBox();
        ((JComboBox)myComponent).setName(name);
        ((JComboBox)myComponent).addMouseListener(new MouseHandler());
        ((JComboBox)myComponent).addMouseMotionListener(new MouseDragHandler());
        ((JComboBox)myComponent).setEnabled(false);
    }
    public String[] getArrangedColumnsNames() { return arrangedColumnsNames; }
    public String getTableNameOutput() { return tableNameOutput; }
    public String getTableNameInput() { return tableNameInput; }
    public String getFieldNameInput() { return fieldNameInput; }
    public Vector getAllColumnsNames() { return allColumnsNames; }
    public Vector getCustomizedTableData() { return customizedTableData; } 
    
    public void fillComboBox()
    {
        if (ComboBoxWizard1.comboBoxWizard1.flag) {
            flag=ComboBoxWizard1.comboBoxWizard5.flagSort;
            tableNameOutput=ComboBoxWizard1.comboBoxWizard3.table;
            allColumnsNames=ComboBoxWizard1.comboBoxWizard4.list2Data;
            tableNameInput=ComboBoxWizard1.comboBoxWizard7.tableNameInput;
            fieldNameInput=ComboBoxWizard1.comboBoxWizard7.fieldNameInput;
 
            switch (flag){
                case 1:arrangedColumnsNames=new String[1];
                       arrangedColumnsNames[0]=ComboBoxWizard1.comboBoxWizard5.columns$1[0];
                       break;
               
                case 2:arrangedColumnsNames=new String[2];
                       arrangedColumnsNames[0]=ComboBoxWizard1.comboBoxWizard5.columns$2[0];
                       arrangedColumnsNames[1]=ComboBoxWizard1.comboBoxWizard5.columns$2[1];
                       break;
               
                case 3:arrangedColumnsNames=new String[3];
                       arrangedColumnsNames[0]=ComboBoxWizard1.comboBoxWizard5.columns$3[0];
                       arrangedColumnsNames[1]=ComboBoxWizard1.comboBoxWizard5.columns$3[1];
                       arrangedColumnsNames[2]=ComboBoxWizard1.comboBoxWizard5.columns$3[2];
                       break;
               
                case 4:arrangedColumnsNames=new String[4];
                       arrangedColumnsNames[0]=ComboBoxWizard1.comboBoxWizard5.columns$4[0];
                       arrangedColumnsNames[1]=ComboBoxWizard1.comboBoxWizard5.columns$4[1];
                       arrangedColumnsNames[2]=ComboBoxWizard1.comboBoxWizard5.columns$4[2];
                       arrangedColumnsNames[3]=ComboBoxWizard1.comboBoxWizard5.columns$4[3];
                       break;
                
                }
    
                for(int i=0;i<arrangedColumnsNames.length;i++){
                    allColumnsNames.removeElement(arrangedColumnsNames[i]);
                }
   
    
            }else
                {
                 int rowLimit=ComboBoxWizard1.comboBoxWizard2.jTable1.getRowCount();
                 int columnLimit=ComboBoxWizard1.comboBoxWizard2.jTable1.getColumnCount();
                 int totalLimit=columnLimit+columnLimit; 
                 for(int i=0;i<totalLimit;i++) {
                     for(int j=0;j<rowLimit;j++){
                         for(int k=0;k<columnLimit;k++){
                             try{
                                    customizedTableData.add(ComboBoxWizard1.comboBoxWizard2.jTable1.getValueAt(j,k));
                                }catch(NullPointerException e){}
                         }
                    }
                }
           }
    }
    //#########################################################################
    public class MouseHandler extends MouseAdapter {
        public void mouseClicked(MouseEvent m) {
            if (m.getButton() == 3) {
                setChosen(true);
                showBorder();
                handleRightClickSelection();
                MyRightClickMenu popUpMenu = new MyRightClickMenu(MyComboBoxContainer.this,m.getX(),m.getY(),frame);
            }
            if (m.getButton()==MouseEvent.BUTTON1) {
                if (m.getClickCount()==2) {
                    JComponent eventObject =(JComponent) m.getComponent(); /* Get the component that is
                     responsable for the action */
                    MyPropertiesWindow properties = new MyPropertiesWindow(MyComboBoxContainer.this,frame);
                    /*Createing the properties window and send the object that is
                     resposable for the event*/
                } else if (m.getClickCount()==1 & m.isShiftDown()==false){
                    if (isChosen()==false) {
                        frame.panel.setCursor(new Cursor(Cursor.HAND_CURSOR));
                        showBorder();
                        setChosen(true);
                    }
                }
            }
        }
        
        public void mousePressed(MouseEvent m) {
            frame.panel.requestFocusInWindow();
            
            if (m.getButton()==MouseEvent.BUTTON1) {
                handleSelection(m);
                frame.panel.setCursor(new Cursor(Cursor.HAND_CURSOR));
                clickToAnchorX=m.getX();
                clickToAnchorY=m.getY();
            }
        }
        
        public void mouseEntered(MouseEvent m) {
            if (((JComboBox)myComponent).isEnabled()==false && isChosen()==true) {
                frame.panel.setCursor(new Cursor(Cursor.HAND_CURSOR));
            }
        }
        
        public void mouseExited(MouseEvent m) {
            frame.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
        
        public void mouseReleased(MouseEvent m) {
            handleUndo();
        }
    }
    //#########################################################################
    class MouseDragHandler extends MouseMotionAdapter {
        public void mouseDragged(MouseEvent evt) {
            handleDrag(evt);
        }
    }
}